<?php
namespace ImiApp\ApiServer\Middleware;

use Imi\RequestContext;
use Imi\Bean\Annotation\Bean;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;

/**
 * @Bean("Index")
 */
class Index implements MiddlewareInterface
{
    /**
     * Process an incoming server request and return a response, optionally delegating
     * response creation to a handler.
     */
    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    {
        if('/index.php' === $request->getUri()->getPath())
        {
            return RequestContext::get('response')->write('imi');
        }
        else
        {
            return $handler->handle($request);
        }
    }

}
